<template>
  <!-- 核查整改 -->
  <view class="rectification">
    <u-tabs
      :list="list"
      lineColor="#00C9AE"
      lineWidth="25"
      :current="activeIndex"
      :inactiveStyle="inactiveStyle"
      :activeStyle="{ color: '#030303' }"
      @click="tabsClick"
    ></u-tabs>

    <view class="wrapper-content">
      <template v-if="activeIndex == 0">
        <scroll-view
          scroll-y="true"
          @scrolltolower="scrollBottom"
          @scroll="scrollHeight"
          :style="[
            {
              height: !loading && !noMore ? '100%' : '100%',
            },
          ]"
          v-if="dataSource.length"
        >
          <view
            class="wrapper-item"
            v-for="(item, i) in dataSource"
            :key="i"
            :data-url="`/verification/rectificDetails/rectificDetails?data=${encodeURIComponent(
              JSON.stringify(item)
            )}`"
            @click="handleClickRouter"
          >
            <view class="md">
              <view class="line-hidden name">
                <text
                  class="timeout"
                  :class="item.type == 1 ? 'fiveOut' : 'offLineOut'"
                >
                  {{ item.type == 1 ? "告警" : "离线" }}超时
                </text>
                {{ item.restaurantName }}-{{ item.deviceName }}
              </view>
              <view class="clause">
                监管单位：<text class="text-class">{{ item.unitName }}</text>
              </view>
              <view class="clause">
                核查城管：
                <text class="text-class">{{ item.policeUserName }}</text>
              </view>
            </view>
            <view class="down">
              <view> 核查时间：{{ item.handleTime }}</view>
              <view style="display: flex"> 查看详情> </view>
            </view>
          </view>
          <view class="pageBottom" v-if="pageBottom">—— 到底了 ——</view>
        </scroll-view>
      </template>

      <template v-if="activeIndex == 1">
        <scroll-view
          scroll-y="true"
          @scrolltolower="scrollBottom"
          @scroll="scrollHeight"
          :style="[
            {
              height: !loading && !noMore ? '100%' : '100%',
            },
          ]"
          v-if="dataSource.length"
        >
          <view
            class="wrapper-item"
            v-for="(item, i) in dataSource"
            :key="i"
            :data-url="`/verification/rectificDetails/rectificHavetodoDet?data=${encodeURIComponent(
              JSON.stringify(item)
            )}`"
            @click="handleClickRouter"
          >
            <view class="md">
              <view class="line-hidden name">
                <text
                  class="timeout"
                  :class="item.type == 1 ? 'fiveOut' : 'offLineOut'"
                >
                  {{ item.type == 1 ? "告警" : "离线" }}超时
                </text>
                {{ item.restaurantName }}-{{ item.deviceName }}
              </view>
              <view class="clause">
                监管单位：<text class="text-class">{{ item.unitName }}</text>
              </view>
              <view class="clause">
                核查城管：
                <text class="text-class">{{ item.policeUserName }}</text>
              </view>
            </view>
            <view class="down">
              <view> 核查时间：{{ item.handleTime }}</view>
              <view style="display: flex"> 查看详情> </view>
            </view>
          </view>
          <view class="pageBottom" v-if="pageBottom">—— 到底了 ——</view>
        </scroll-view>
      </template>

      <view v-if="!dataSource.length">
        <u-empty
          mode="list"
          text="暂无内容！"
          :icon="baseImgUrl + 'no-icon2.png'"
        >
        </u-empty>
      </view>
    </view>
  </view>
</template>

<script>
import { workOrderRecordPage } from "@/api/home.js";
import { handleClickRouter } from "@/utils/util.js";

export default {
  data() {
    return {
      activeIndex: 0,
      baseImgUrl: this.$baseImgUrl,
      scrollTop: 0,
      list: [
        {
          name: "待办",
          badge: {
            isDot: false,
          },
        },
        {
          name: "已办",
          badge: {
            isDot: false,
          },
        },
      ],
      dataSource: [],
      pageBottom: false,
      pageConfig: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  onLoad() {
    this.scrollTop = 0;
    uni.removeStorageSync("scrollTop");

    this.pageConfig.pageNo = 1;
    this.dataSource = [];
    this.getList();
  },
  onShow() {
    this.scrollTop = uni.getStorageSync("scrollTop") || 0;

    uni.$on("rectification", () => {
      this.pageConfig.pageNo = 1;
      this.dataSource = [];
      this.getList();
    });
  },
  methods: {
    handleClickRouter,
    scrollHeight(e) {
      uni.setStorageSync("scrollTop", e.detail.scrollTop);
    },
    scrollBottom(e) {
      let current = (this.pageConfig.pageNo += 1);
      let pages = Math.ceil(this.pageConfig.total / this.pageConfig.pageSize);
      if (current <= pages) {
        this.getList();
      } else {
        this.pageBottom = true;
      }
    },
    tabsClick(item) {
      this.scrollTop = 0;
      uni.removeStorageSync("scrollTop");

      this.activeIndex = item.index;
      this.pageConfig.pageNo = 1;
      this.dataSource = [];
      this.getList();
    },
    getList() {
      // status   2待办    3已办
      let data = {
        status: this.activeIndex + 2,
        pageNo: this.pageConfig.pageNo,
        pageSize: this.pageConfig.pageSize,
      };

      workOrderRecordPage(data).then((res) => {
        this.dataSource = this.dataSource.concat(res.result.records || []);
        this.pageConfig.total = res.result.total;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.rectification {
  height: 100%;

  .wrapper-content {
    padding: 24rpx 16rpx;
    background: #f8f9fb;
    height: calc(100vh - 45px);

    .wrapper-item {
      padding: 30rpx;
      padding-bottom: 0;
      background-color: #ffffff;
      margin-bottom: 20rpx;

      .md {
        border-bottom: 1rpx solid #e4e4e4;

        .name {
          font-size: 30rpx;
          font-family: PingFang SC;
          font-weight: bold;
          margin-bottom: 17rpx;
        }

        .timeout {
          display: inline-block;
          margin-right: 8rpx;
          padding: 2rpx 8rpx;
          font-size: 26rpx;
          font-weight: 400;
          border-radius: 8rpx;
        }

        // 告警
        .fiveOut {
          color: #e85656;
          border: 1px solid #f8afaf;
          background: #ffdede;
        }

        // 离线
        .offLineOut {
          color: #f39835;
          background: #fef4e9;
          border: 1px solid #ffd3a4;
        }

        .clause {
          margin-bottom: 20rpx;
          font-size: 26rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #a1a1a1;

          .text-class {
            color: #333333;
          }
        }
      }

      .down {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        padding: 20rpx 0;
        font-size: 28rpx;
        font-weight: 400;
        color: #bbbbbb;
      }
    }
  }
}
</style>
